package hlhj.fhp.drawskin

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.JavascriptInterface
import android.webkit.WebChromeClient
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.Toast
import com.tenma.ventures.base.TMWebFragment
import com.tenma.ventures.bean.utils.TMSharedPUtil
import com.tenma.ventures.config.TMServerConfig

/**
 * Created by Never Fear   on 2018\11\14 0014.
Never More....
 */
class WebFgm :Fragment() {
    private var rootView:View?=null
    private var webView:WebView?=null
    @SuppressLint("JavascriptInterface")
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        rootView=inflater.inflate(R.layout.fgm_draw_web,null)

        webView=rootView?.findViewById<WebView>(R.id.webView)
        webView!!.settings.javaScriptEnabled=true
        webView!!.webViewClient=object : WebViewClient(){}
        webView!!.webChromeClient=object : WebChromeClient(){}


        webView?.addJavascriptInterface(this,"tmAndroidInf")
        webView?.loadUrl("http://tianma.wufenhuyu.com/application/hlhj_transferlottery/wap/#/")
//        webView?.loadUrl("${TMServerConfig.BASE_URL}/application/hlhj_transferlottery/wap?token=${TMSharedPUtil.getTMToken(context)}&member_code=${TMSharedPUtil.getTMUser(context).member_code}")
//        webView?.loadUrl("${TMServerConfig.BASE_URL}/application/hlhj_transferlottery/wap?token=${TMSharedPUtil.getTMToken(context)}&member_code=${TMSharedPUtil.getTMUser(context).member_code}")
        return rootView

    }


    @JavascriptInterface
    open fun goLogin(){
        Toast.makeText(context,"用户信息过期，重新登录", Toast.LENGTH_SHORT).show()
        val action = context!!.packageName + ".usercenter.login"
        val intent = Intent(action)
        startActivity(intent)
        activity?.finish()
    }
}